﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SysContext;
using Business_Logic_Layer;
using DataAccessLayer;

namespace Money_Dance
{
    public partial class UserControlCheckingAccount : UserControl
    {
        DateTime date = DateTime.Now;
        SysDataContext Data = new SysDataContext();
        BUSS BUS = new BUSS();


        TransactionsTable TransTable = new TransactionsTable();
        TransactionReminderTable ReminderTable = new TransactionReminderTable();
              
        public static string AccountType;
        public static int UserID;       

        public UserControlCheckingAccount()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Constructor UserControlCheckingAccount
        /// </summary>
        /// <param name="id"></param>
        public UserControlCheckingAccount(int id)
        {
            UserID = id;
        }

        /// <summary>
        /// Constructor UserControlCheckingAccount
        /// </summary>
        /// <param name="Id_Acc"></param>
        /// <param name="Id_User"></param>
        public UserControlCheckingAccount(string Id_Acc, int Id_User)
        {
            AccountType = Id_Acc;
            UserID = Id_User;
        }
                
        private void btn_Taomoi_Click(object sender, EventArgs e)
        {       
            GroupBoxTaoMoi.Visible = true;
            btn_Capnhat.Enabled = true;
            //Đỗ dữ liệu danh mục vào Combobox.
            CbbHinhThuc.DataSource = BUS.SelectName();
        }        
        
        private void btn_Capnhat_Click(object sender, EventArgs e)
        {                   
            double bal = 0;  
            bal = double.Parse(TbxSoTienChi.Text); 
            //Gọi hàm InsertTransaction từ lớp BUSS.
            BUS.InsertTransation(UserID, AccountType, int.Parse(TbxSoTienChi.Text), int.Parse(TbxSoTienThu.Text),DateTime.Parse(date.ToShortDateString()), BUS.GetIdCategory(CbbHinhThuc.Text), TbxLyDo.Text, bal);
            SetText();
            dataGridViewChecking.AutoGenerateColumns = false;
            dataGridViewChecking.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue;
            dataGridViewChecking.DataSource = BUS.SelectTrans(UserID, AccountType);          
        }

        public void Clear()
        {
            TbxLyDo.Clear();
            TbxSoTienChi.Clear();
            TbxSoTienThu.Clear();
        }
        // Thiết lập nội dung các Texbox trước khi nhập dữ liệu.
        public void SetText()
        {
            TbxLyDo.Text = "Lý do";
            TbxSoTienChi.Text = " Số tiền chi";
            TbxSoTienThu.Text = "Số tiền thu";
        }

        private void TbxSoTienChi_Click(object sender, EventArgs e)
        {
            TbxSoTienChi.Clear();
            TbxSoTienThu.Text = "0";
        }

        private void TbxSoTienThu_Click(object sender, EventArgs e)
        {
            TbxSoTienThu.Clear();
            TbxSoTienChi.Text = "0";            
        }

        private void TbxLyDo_Click(object sender, EventArgs e)
        {
            TbxLyDo.Clear();            
        }
        /// <summary>
        /// Đỗ dữ liệu vào bảng theo từng User và tài khoản
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControlTaiKhoan_Load(object sender, EventArgs e)
        {
            this.TbxSoTienThu.Enabled = false;
            BUS.CountOccurredDate(UserID, AccountType, DateTime.Parse(date.ToShortDateString()));
            dataGridViewChecking.AutoGenerateColumns = false;
            dataGridViewChecking.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue;            
            dataGridViewChecking.DataSource = BUS.SelectTrans(UserID, AccountType);            
        }

    }
}
